/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tpgen;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationProperty;
import org.semanticweb.owlapi.model.OWLAnnotationPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLAnnotationPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLAnonymousIndividual;
import org.semanticweb.owlapi.model.OWLAsymmetricObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLAxiom;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLDataAllValuesFrom;
import org.semanticweb.owlapi.model.OWLDataComplementOf;
import org.semanticweb.owlapi.model.OWLDataExactCardinality;
import org.semanticweb.owlapi.model.OWLDataHasValue;
import org.semanticweb.owlapi.model.OWLDataIntersectionOf;
import org.semanticweb.owlapi.model.OWLDataMaxCardinality;
import org.semanticweb.owlapi.model.OWLDataMinCardinality;
import org.semanticweb.owlapi.model.OWLDataOneOf;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLDataUnionOf;
import org.semanticweb.owlapi.model.OWLDatatype;
import org.semanticweb.owlapi.model.OWLDatatypeDefinitionAxiom;
import org.semanticweb.owlapi.model.OWLDatatypeRestriction;
import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom;
import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
import org.semanticweb.owlapi.model.OWLDisjointDataPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLDisjointObjectPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLDisjointUnionAxiom;
import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
import org.semanticweb.owlapi.model.OWLEquivalentDataPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLFacetRestriction;
import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom;
import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLHasKeyAxiom;
import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom;
import org.semanticweb.owlapi.model.OWLIrreflexiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLLiteral;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLNegativeDataPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectComplementOf;
import org.semanticweb.owlapi.model.OWLObjectExactCardinality;
import org.semanticweb.owlapi.model.OWLObjectHasSelf;
import org.semanticweb.owlapi.model.OWLObjectHasValue;
import org.semanticweb.owlapi.model.OWLObjectIntersectionOf;
import org.semanticweb.owlapi.model.OWLObjectInverseOf;
import org.semanticweb.owlapi.model.OWLObjectMaxCardinality;
import org.semanticweb.owlapi.model.OWLObjectMinCardinality;
import org.semanticweb.owlapi.model.OWLObjectOneOf;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
import org.semanticweb.owlapi.model.OWLObjectSomeValuesFrom;
import org.semanticweb.owlapi.model.OWLObjectUnionOf;
import org.semanticweb.owlapi.model.OWLObjectVisitor;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLSameIndividualAxiom;
import org.semanticweb.owlapi.model.OWLSubAnnotationPropertyOfAxiom;
import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom;
import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom;
import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom;
import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom;
import org.semanticweb.owlapi.model.SWRLBuiltInAtom;
import org.semanticweb.owlapi.model.SWRLClassAtom;
import org.semanticweb.owlapi.model.SWRLDataPropertyAtom;
import org.semanticweb.owlapi.model.SWRLDataRangeAtom;
import org.semanticweb.owlapi.model.SWRLDifferentIndividualsAtom;
import org.semanticweb.owlapi.model.SWRLIndividualArgument;
import org.semanticweb.owlapi.model.SWRLLiteralArgument;
import org.semanticweb.owlapi.model.SWRLObjectPropertyAtom;
import org.semanticweb.owlapi.model.SWRLRule;
import org.semanticweb.owlapi.model.SWRLSameIndividualAtom;
import org.semanticweb.owlapi.model.SWRLVariable;
import org.semanticweb.owlapi.util.OWLClassExpressionCollector;
import tpgen.manchester.w3org.Construct;

/**
 *
 * @author shanki
 */
public class Analyser {
    public Set<Construct> analyse(OWLOntology ontology) {
        Set<Construct> constructs = new HashSet<Construct>();
                
        OWLClassExpressionCollector col = new OWLClassExpressionCollector();        
        Set<OWLClassExpression> es      = col.visit(ontology);
                
        CEVisitor visitor               = new CEVisitor(constructs);
        
        for (OWLClassExpression e : es) {
            e.accept(visitor);
        }
        
        
        Set<OWLAxiom> axioms        = ontology.getAxioms();        
        
        for (OWLAxiom axiom : axioms) {
            axiom.accept(visitor);
        }        
        
        return constructs;
    }

    private static class CEVisitor implements OWLObjectVisitor {

        private Collection<Construct> constructs;

        private CEVisitor(Collection<Construct> constructs) {
            this.constructs = constructs;
        }

        @Override
        public void visit(OWLOntology owlo) {
            // nothing to do
        }

        @Override
        public void visit(OWLDeclarationAxiom owlda) {
            // ??
        }

        @Override
        public void visit(OWLSubClassOfAxiom owlsc) {
            constructs.add(Construct.classFrame);
            constructs.add(Construct.classFrameSubClassOf);
        }

        @Override
        public void visit(OWLNegativeObjectPropertyAssertionAxiom owlnp) {
            constructs.add(Construct.individualFrame);
            constructs.add(Construct.individualFrameFacts);
            constructs.add(Construct.factNot);
        }

        @Override
        public void visit(OWLAsymmetricObjectPropertyAxiom owlp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameCharacteristics);
            constructs.add(Construct.objectPropertyCharacteristicsAsymmetric);
        }

        @Override
        public void visit(OWLReflexiveObjectPropertyAxiom owlrp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameCharacteristics);
            constructs.add(Construct.objectPropertyCharacteristicsReflexive);
        }

        @Override
        public void visit(OWLDisjointClassesAxiom owldca) {
            constructs.add(Construct.classFrame);
            constructs.add(Construct.classFrameDisjointWith);
        }

        @Override
        public void visit(OWLDataPropertyDomainAxiom owldpd) {
            constructs.add(Construct.dataPropertyFrame);
            constructs.add(Construct.dataPropertyFrameDomain);
        }

        @Override
        public void visit(OWLObjectPropertyDomainAxiom owlpd) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameDomain);
        }

        @Override
        public void visit(OWLEquivalentObjectPropertiesAxiom owlp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameEquivalentTo);
        }

        @Override
        public void visit(OWLNegativeDataPropertyAssertionAxiom owlndp) {
            constructs.add(Construct.individualFrame);
            constructs.add(Construct.individualFrameFacts);
            constructs.add(Construct.factDataProperty);
            constructs.add(Construct.factNot);
        }

        @Override
        public void visit(OWLDifferentIndividualsAxiom owldia) {
            constructs.add(Construct.individualFrame);
            constructs.add(Construct.individualFrameDifferentFrom);
        }

        @Override
        public void visit(OWLDisjointDataPropertiesAxiom owldp) {
            constructs.add(Construct.dataPropertyFrame);
            constructs.add(Construct.dataPropertyFrameDisjointWith);
        }

        @Override
        public void visit(OWLDisjointObjectPropertiesAxiom owldp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameDisjointWith);
        }

        @Override
        public void visit(OWLObjectPropertyRangeAxiom owlpr) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameRange);
        }

        @Override
        public void visit(OWLObjectPropertyAssertionAxiom owlp) {
            constructs.add(Construct.individualFrame);
            constructs.add(Construct.individualFrameFacts);
            constructs.add(Construct.factObjectProperty);
        }

        @Override
        public void visit(OWLFunctionalObjectPropertyAxiom owlfp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameCharacteristics);
            constructs.add(Construct.objectPropertyCharacteristicsFunctional);
        }

        @Override
        public void visit(OWLSubObjectPropertyOfAxiom owlsp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameSubPropertyOf);
        }

        @Override
        public void visit(OWLDisjointUnionAxiom owldua) {
            constructs.add(Construct.classFrame);
            constructs.add(Construct.classFrameDisjointUnionOf);
        }

        @Override
        public void visit(OWLSymmetricObjectPropertyAxiom owlsp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameCharacteristics);
            constructs.add(Construct.objectPropertyCharacteristicsSymmetric);
        }

        @Override
        public void visit(OWLDataPropertyRangeAxiom owldpr) {
            constructs.add(Construct.dataPropertyFrame);
            constructs.add(Construct.dataPropertyFrameRange);
        }

        @Override
        public void visit(OWLFunctionalDataPropertyAxiom owlfdp) {
            constructs.add(Construct.dataPropertyFrame);
            constructs.add(Construct.dataPropertyFrameCharacteristics);
        }

        @Override
        public void visit(OWLEquivalentDataPropertiesAxiom owldp) {
            constructs.add(Construct.dataPropertyFrame);
            constructs.add(Construct.dataPropertyFrameEquivalentTo);
        }

        @Override
        public void visit(OWLClassAssertionAxiom owlcaa) {
            constructs.add(Construct.individualFrame);
            constructs.add(Construct.individualFrameTypes);
        }

        @Override
        public void visit(OWLEquivalentClassesAxiom owleca) {
            constructs.add(Construct.classFrame);
            constructs.add(Construct.classFrameEquivalentTo);
        }

        @Override
        public void visit(OWLDataPropertyAssertionAxiom owldp) {
            constructs.add(Construct.individualFrame);
            constructs.add(Construct.individualFrameFacts);
            constructs.add(Construct.factDataProperty);
        }

        @Override
        public void visit(OWLTransitiveObjectPropertyAxiom owltp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameCharacteristics);
            constructs.add(Construct.objectPropertyCharacteristicsTransitive);
        }

        @Override
        public void visit(OWLIrreflexiveObjectPropertyAxiom owlp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameCharacteristics);
            constructs.add(Construct.objectPropertyCharacteristicsIrreflexive);
        }

        @Override
        public void visit(OWLSubDataPropertyOfAxiom owlsdp) {
            constructs.add(Construct.dataPropertyFrame);
            constructs.add(Construct.dataPropertyFrameSubPropertyOf);
        }

        @Override
        public void visit(OWLInverseFunctionalObjectPropertyAxiom owlfp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameCharacteristics);
            constructs.add(Construct.objectPropertyCharacteristicsInverseFunctional);
        }

        @Override
        public void visit(OWLSameIndividualAxiom owlsia) {
            constructs.add(Construct.individualFrame);
            constructs.add(Construct.individualFrameSameAs);
        }

        @Override
        public void visit(OWLSubPropertyChainOfAxiom owlspc) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameSubPropertyChain);
        }

        @Override
        public void visit(OWLInverseObjectPropertiesAxiom owlp) {
            constructs.add(Construct.objectPropertyFrame);
            constructs.add(Construct.objectPropertyFrameInverseOf);
        }

        @Override
        public void visit(OWLHasKeyAxiom owlhka) {
            // we do not have this
        }

        @Override
        public void visit(OWLDatatypeDefinitionAxiom owldda) {
            // we do not have this
        }

        @Override
        public void visit(SWRLRule swrlr) {
            // ??
        }

        @Override
        public void visit(OWLAnnotationAssertionAxiom owlaaa) {
            // we do not have this
        }

        @Override
        public void visit(OWLSubAnnotationPropertyOfAxiom owlsp) {
            // we do not have this
        }

        @Override
        public void visit(OWLAnnotationPropertyDomainAxiom owlpd) {
            // we do not have this
        }

        @Override
        public void visit(OWLAnnotationPropertyRangeAxiom owlpr) {
            // we do not have this
        }

        @Override
        public void visit(OWLClass owlc) {
            // do nothing
        }

        @Override
        public void visit(OWLObjectIntersectionOf owloio) {
            constructs.add(Construct.conjunctionAnd);
        }

        @Override
        public void visit(OWLObjectUnionOf owlouo) {
            constructs.add(Construct.descriptionOr);
        }

        @Override
        public void visit(OWLObjectComplementOf owloco) {
            constructs.add(Construct.primaryNot);
        }

        @Override
        public void visit(OWLObjectSomeValuesFrom owlsvf) {
            constructs.add(Construct.restrictionObjectSome);
        }

        @Override
        public void visit(OWLObjectAllValuesFrom owlvf) {
            constructs.add(Construct.restrictionObjectOnly);
        }

        @Override
        public void visit(OWLObjectHasValue owlohv) {
            constructs.add(Construct.restrictionObjectValue);
        }

        @Override
        public void visit(OWLObjectMinCardinality owlomc) {
            constructs.add(Construct.restrictionObjectMin);
        }

        @Override
        public void visit(OWLObjectExactCardinality owloec) {
            constructs.add(Construct.restrictionObjectExactly);
        }

        @Override
        public void visit(OWLObjectMaxCardinality owlomc) {
            constructs.add(Construct.restrictionObjectMax);
        }

        @Override
        public void visit(OWLObjectHasSelf owlohs) {
            constructs.add(Construct.restrictionObjectSelf);
        }

        @Override
        public void visit(OWLObjectOneOf owlooo) {
            constructs.add(Construct.atomicIndividualList);
        }

        @Override
        public void visit(OWLDataSomeValuesFrom o) {
            constructs.add(Construct.restrictionDataSome);
        }

        @Override
        public void visit(OWLDataAllValuesFrom owldvf) {
            constructs.add(Construct.restrictionDataOnly);
        }

        @Override
        public void visit(OWLDataHasValue owldhv) {
            constructs.add(Construct.restrictionDataValue);
        }

        @Override
        public void visit(OWLDataMinCardinality owldmc) {
            constructs.add(Construct.restrictionDataMin);
        }

        @Override
        public void visit(OWLDataExactCardinality owldec) {
            constructs.add(Construct.restrictionDataExactly);
        }

        @Override
        public void visit(OWLDataMaxCardinality owldmc) {
            constructs.add(Construct.restrictionDataMax);
        }

        @Override
        public void visit(OWLLiteral owll) {
            // do nothing
        }

        @Override
        public void visit(OWLFacetRestriction owlfr) {
            constructs.add(Construct.dataAtomicDataTypeRestriction);
        }

        @Override
        public void visit(OWLDatatype owld) {
            // do nothing
        }

        @Override
        public void visit(OWLDataOneOf owldoo) {
            constructs.add(Construct.dataAtomicLiteralList);
        }

        @Override
        public void visit(OWLDataComplementOf owldco) {
            constructs.add(Construct.dataPrimaryNot);
        }

        @Override
        public void visit(OWLDataIntersectionOf owldio) {
            constructs.add(Construct.dataConjunctionAnd);
        }

        @Override
        public void visit(OWLDataUnionOf owlduo) {
            constructs.add(Construct.dataRangeOr);
        }

        @Override
        public void visit(OWLDatatypeRestriction owldr) {
            constructs.add(Construct.dataAtomicDataTypeRestriction);
        }

        @Override
        public void visit(OWLObjectProperty owlop) {
            // do nothing
        }

        @Override
        public void visit(OWLObjectInverseOf owloio) {
            constructs.add(Construct.objectPropertyExpressionInverse);
        }

        @Override
        public void visit(OWLDataProperty owldp) {
            // do nothing
        }

        @Override
        public void visit(OWLNamedIndividual owlni) {
            // do nothing
        }

        @Override
        public void visit(OWLAnnotationProperty owlap) {
            // do nothing
        }

        @Override
        public void visit(OWLAnonymousIndividual owlai) {
            // do nothing
        }

        @Override
        public void visit(IRI iri) {
            // do nothing
        }

        @Override
        public void visit(OWLAnnotation owla) {
            // do nothing
        }

        @Override
        public void visit(SWRLClassAtom swrlca) {
            // do nothing
        }

        @Override
        public void visit(SWRLDataRangeAtom swrldr) {
            // do nothing
        }

        @Override
        public void visit(SWRLObjectPropertyAtom swrlp) {
            // do nothing
        }

        @Override
        public void visit(SWRLDataPropertyAtom swrldp) {
            // do nothing
        }

        @Override
        public void visit(SWRLBuiltInAtom swrlb) {
            // do nothing
        }

        @Override
        public void visit(SWRLVariable swrlv) {
            // do nothing
        }

        @Override
        public void visit(SWRLIndividualArgument swrlia) {
            // do nothing
        }

        @Override
        public void visit(SWRLLiteralArgument swrlla) {
            // do nothing
        }

        @Override
        public void visit(SWRLSameIndividualAtom swrls) {
            // do nothing
        }

        @Override
        public void visit(SWRLDifferentIndividualsAtom swrld) {
            // do nothing
        }
    }
}
